import sys; sys.stdout.reconfigure(encoding='utf-8')
import io
import ddddocr
from PIL import Image
import base64
Image.ANTIALIAS = Image.LANCZOS  # 定义别名




def dddd_ocr_text(data):
    """
    进行OCR识别的函数
    :param data:
    :return:
    """
    encode_data = data.split(',')[1]
    decode_data = base64.b64decode(encode_data)
    #把解码数据调整为图像数据
    image = Image.open(io.BytesIO(decode_data))

    #把图像数据转成字节数据
    image_bytes = io.BytesIO()
    image.save(image_bytes, format='PNG')
    image_bytes = image_bytes.getvalue()

    #初始化
    ocr = ddddocr.DdddOcr()
    text = ocr.classification(image_bytes)

    return text


